{extend name="common:base" /}

{block name="title"}系统管理 - {$config.site_name}{/block}

{block name="main"}
<div class="mdui-container">
  <main>
    <div class="system-container">
      <div class="mdui-typo">
        <blockquote class="mdui-m-l-0">
          <p>
            系统配置，统计代码中注意要使用&lt;script&gt;&lt;/script&gt;标签，不设置可为空。<br>
            基础配置如果出现无法保存的情况请检查请求是否被防火墙拦截。
          </p>
        </blockquote>
      </div>
      <div class="mdui-tab mdui-tab-scrollable" mdui-tab>
        <a href="#tab-basics" class="mdui-ripple">基础配置</a>
        <a href="#tab-upload" class="mdui-ripple">上传配置</a>
        <a href="#tab-user" class="mdui-ripple">用户配置</a>
        <a href="#tab-mail" class="mdui-ripple">邮件配置</a>
        <a href="#tab-other" class="mdui-ripple">其他配置</a>
        <a href="#tab-audit" class="mdui-ripple">图片鉴黄</a>
      </div>
      <div class="tabs mdui-col-sm-8 mdui-col-md-8">
        {foreach $configs as $key => $value}
        <div id="tab-{$key}" class="mdui-p-a-2" style="display: none;">
          <form action="{:url('admin/system/index')}" method="post">
            {foreach $value as $val}
            <div class="mdui-textfield">
              <label class="mdui-textfield-label">{$val.title}{$val.tip ? '(' . $val.tip . ')' : ''}</label>
              {switch $val.type}
              {case text}
              <input class="mdui-textfield-input" type="{$val.input_type}" name="{$val.name}" value="{$val.value}" autocomplete="off" placeholder="{$val.title}"/>
              {/case}
              {case textarea}
              <textarea class="mdui-textfield-input" rows="6" name="{$val.name}" autocomplete="off" placeholder="{$val.title}">{$val.value}</textarea>
              {/case}
              {case bool}
              <label class="mdui-switch">
                <input type="{$val.input_type}" data-name="{$val.name}" value="1" {if 1 eq $val.value}checked{/if}/>
                <i class="mdui-switch-icon"></i>
              </label>
              {/case}
              {case select}
              <select name="{$val.name}" class="mdui-select" mdui-select>
                {foreach $val.extend as $k => $v}
                <option value="{$k}" {if $k eq $val.value}selected{/if}>{$v}</option>
                {/foreach}
              </select>
              {/case}
              {/switch}
            </div>
            {/foreach}
            <button type="submit" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent">保存</button>
            <button type="reset" class="mdui-btn mdui-btn-raised mdui-ripple">重置</button>
            {if 'mail' eq $key}
            <!-- 测试邮件发送 -->
            <button type="button" id="test-send-mail" class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-cyan-600 mdui-text-color-white">测试邮件发送</button>
            {/if}
          </form>
        </div>
        {/foreach}
      </div>
    </div>
  </main>
  <div class="mdui-dialog" id="path-var">
    <div class="mdui-dialog-content mdui-p-a-0">
      <div class="mdui-table-fluid">
        <table class="mdui-table mdui-table-hoverable">
          <thead>
          <tr>
            <th>变量名</th>
            <th>示例</th>
            <th>说明</th>
          </tr>
          </thead>
          <tbody>
          {foreach $naming.path as $value}
          <tr>
            <td>{$value.name}</td>
            <td>{$value.example}</td>
            <td>{$value.explain}</td>
          </tr>
          {/foreach}
          </tbody>
        </table>
      </div>
    </div>
  </div>
  <div class="mdui-dialog" id="file-var">
    <div class="mdui-dialog-content mdui-p-a-0">
      <div class="mdui-table-fluid">
        <table class="mdui-table mdui-table-hoverable">
          <thead>
          <tr>
            <th>变量名</th>
            <th>示例</th>
            <th>说明</th>
          </tr>
          </thead>
          <tbody>
          {foreach $naming.file as $value}
          <tr>
            <td>{$value.name}</td>
            <td>{$value.example}</td>
            <td>{$value.explain}</td>
          </tr>
          {/foreach}
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
{/block}
{block name="js"}
<script>
  $(function () {

    $('form').submit(function (e) {
      e.preventDefault();
      var data = $(this).serialize();
      $(this).find("input[type='checkbox']").each(function (key, value) {
        data += ("&" + $(value).data('name') + "=") + (value.checked ? value.value : 0);
      });
      app.request(this.action, data)
    });

    $('#test-send-mail').click(function () {
      mdui.prompt('请输入邮箱',
        function (value) {
          app.request("{:url('admin/system/testMail')}", {email: value});
        },
        function (value) {

        },
        {
          confirmText: '确定',
          cancelText: '取消'
        }
      );
    });
  });
</script>
{/block}
